package com.tanhua.api.db;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.vo.PageBeanVo;
import com.tanhua.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service // 注解使用dubbo的
public class UserInfoApiImpl implements UserInfoApi {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo findByUserId(Long userId) {
        return userInfoMapper.selectById(userId);
    }

    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize) {
        IPage page = new Page<UserInfo>(pageNum, pageSize);
        page = userInfoMapper.selectPage(page, null);
        return new PageBeanVo(pageNum, pageSize, page.getTotal(), page.getRecords());
    }
}
